package org.dioib.practice.controller;

import org.dioib.practice.mapper.DiscardSysUserMapper;
import org.dioib.practice.model.SysUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
@RestController
@RequestMapping("/user")
public class SysUserController {
    @Autowired
    private DiscardSysUserMapper discardSysUserMapper;

    @GetMapping
    public List<SysUser> findAll(){
        return discardSysUserMapper.findAll();
    }

    @GetMapping("/one")
    public List<SysUser> findOne(String firstName){
        return discardSysUserMapper.findOne(firstName);
    }

    @PostMapping("/add")
    public int addUser(SysUser user){
        System.out.printf("PostMapping add user");
        return discardSysUserMapper.insert(user);
    }

    @PostMapping("/add1")
    public int addUser1(@RequestBody SysUser user){
        System.out.printf("PostMapping and RequestBody add user");
        return discardSysUserMapper.insert(user);
    }

    @PutMapping("/add")
    public int insert(SysUser user){
        System.out.printf("PutMapping add user");
        return discardSysUserMapper.insert(user);
    }

    @DeleteMapping("/del")
    public int delete(SysUser sysUser){
        return discardSysUserMapper.delete(sysUser);
    }

    @PutMapping("/put")
    public int update(SysUser sysUser){
        return discardSysUserMapper.update(sysUser);
    }


    @GetMapping("/halo")
    public String index(){
        //return sysUserMapper.findAll();
        return "halo";
    }

}
